home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / telecomm / misc / linkz88.lha / LinkZ88 / Source / general.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-12  |  6.2 KB  |  306 lines

  1. /************************************************
  2.  **************    general.c   ******************
  3.  ************************************************/
  4.  
  5. #define INTUI_V36_NAMES_ONLY
  6.  
  7. #include <exec/exec.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <workbench/startup.h>
  11. #include <libraries/gadtools.h>
  12. #include <graphics/gfxbase.h>
  13. #include <devices/serial.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/intuition_protos.h>
  17. #include <clib/icon_protos.h>
  18. #include <clib/alib_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/dos_protos.h>
  21. #include <clib/wb_protos.h>
  22.  
  23. #include <string.h>
  24.  
  25. #include "windows.h"
  26.  
  27. #include "consts.h"
  28. #include "structs.h"
  29. #include "protos.h"
  30.  
  31. extern prj_p prj;
  32.  
  33. /* Wait pointer */
  34.  
  35. #ifdef _DCC
  36. __chip UWORD WaitPointer[] = {
  37. #else
  38. UWORD __chip WaitPointer[] = {
  39. #endif
  40.     0x0000, 0x0000,     /* reserved, must be NULL */
  41.  
  42.     0x0400, 0x07C0,
  43.     0x0000, 0x07C0,
  44.     0x0100, 0x0380,
  45.     0x0000, 0x07E0,
  46.     0x07C0, 0x1FF8,
  47.     0x1FF0, 0x3FEC,
  48.     0x3FF8, 0x7FDE,
  49.     0x3FF8, 0x7FBE,
  50.     0x7FFC, 0xFF7F,
  51.     0x7EFC, 0xFFFF,
  52.     0x7FFC, 0xFFFF,
  53.     0x3FF8, 0x7FFE,
  54.     0x3FF8, 0x7FFE,
  55.     0x1FF0, 0x3FFC,
  56.     0x07C0, 0x1FF8,
  57.     0x0000, 0x07E0,
  58.  
  59.     0x0000, 0x0000,     /* reserved, must be NULL */
  60.     };
  61.  
  62.  
  63. /*
  64. Function : void startup(int argc,char **argv)
  65. Purpose : Sets up the program before start. Reads tooltypes from command line
  66.     or icon.
  67. */
  68.  
  69. void startup(int argc,char **argv)
  70. {
  71.     WORD l;
  72.  
  73.     /* NULL pointers first */
  74.  
  75.     prj->serial_msg_port = NULL;
  76.     prj->serialio = NULL;
  77.     prj->serial_open = FALSE;
  78.  
  79.     for (l = 0; l < MAX_LISTVIEW_ENTRIES; l++)
  80.         prj->listviewarray[l] = NULL;
  81.  
  82.     NewList(&prj->listviewlist);
  83.  
  84.     prj->zpath[0] = '\0';
  85.     prj->zpathdepth = -1;
  86.  
  87.     prj->path_binary_get[0] = '\0';
  88.     prj->path_binary_put[0] = '\0';
  89.  
  90.     prj->blocked = FALSE;
  91.  
  92.     /* Create the serial message port */
  93.  
  94.     prj->serial_msg_port = CreatePort(NULL,NULL);
  95.  
  96.     if (!prj->serial_msg_port)
  97.         error("Can't create serial message port",ERROR_FATAL,
  98. __LINE__,__FILE__);
  99.  
  100.     /* Set up the serial device */
  101.  
  102.     prj->serialio = (struct IOExtSer *)CreateExtIO(
  103. prj->serial_msg_port,sizeof(struct IOExtSer));
  104.  
  105.     if (!prj->serialio)
  106.         error("Can't set up serial device",ERROR_FATAL,__LINE__,
  107. __FILE__);
  108.  
  109.     if (OpenDevice(SERIALNAME,0,(struct IORequest *)prj->serialio,NULL))
  110.         error("Can't open serial device",ERROR_FATAL,__LINE__,
  111. __FILE__);
  112.  
  113.     prj->serial_open = TRUE;
  114.  
  115. }
  116.  
  117.  
  118. /*
  119. Function : void error(const char *msg,error_e err_no,int line,const char *file);
  120. Purpose : Pops up a requester informing user of an error. If err_no ==
  121.     ERROR_WARN, a requester is displayed informing the user of the error.
  122.     If err_no == ERROR_FATAL, the function calls cleanup() and the program
  123.     will exit. err_no == ERROR_INTERNAL is like ERROR_FATAL, only the line
  124.     and file of the error is also displayed. The user may split the error
  125.     message into a terse and a verbose section with the use of the '|'
  126.     character. The terse message has "More..." and "Continue" buttons.
  127. */
  128.  
  129. void error(const char *msg,error_e err_no,int line,const char *file)
  130. {
  131.     struct Window *window = NULL;
  132.  
  133.     struct EasyStruct easyreq_internal = {
  134.         sizeof(struct EasyStruct),
  135.         0,
  136.         VERSION_SHORTNAME,
  137.         NULL,
  138.         "Quit"
  139.     };
  140.  
  141.     struct EasyStruct easyreq_fatal = {
  142.         sizeof(struct EasyStruct),
  143.         0,
  144.         VERSION_SHORTNAME,
  145.         "FATAL ERROR :\n%s",
  146.         "Quit"
  147.     };
  148.  
  149.     struct EasyStruct easyreq_warn = {
  150.         sizeof(struct EasyStruct),
  151.         0,
  152.         VERSION_SHORTNAME,
  153.         NULL,
  154.         "Continue"
  155.     };
  156.     
  157.     struct EasyStruct easyreq_more = {
  158.         sizeof(struct EasyStruct),
  159.         0,
  160.         VERSION_SHORTNAME,
  161.         "%s",
  162.         "More...|Continue"
  163.     };
  164.  
  165.     struct EasyStruct easyreq_fatalmore = {
  166.         sizeof(struct EasyStruct),
  167.         0,
  168.         VERSION_SHORTNAME,
  169.         "%s",
  170.         "More...|Quit"
  171.     };
  172.  
  173.     BOOL unblock = TRUE;
  174.  
  175.     char reqtext[STRLEN_EASYREQ];
  176.  
  177.     char terse[STRLEN_ERRMSG];
  178.     char *verbose = NULL;
  179.  
  180.     size_t terse_length;
  181.  
  182.     /* Don't unblock the main window after requester if it's */
  183.     /* already blocked. */
  184.  
  185.     if (prj->blocked)
  186.         unblock = FALSE;
  187.     else
  188.         win_block_set();
  189.  
  190.     /* Point the verbose pointer to the character after the '|' */
  191.  
  192.     verbose = strstr(msg,"|");
  193.  
  194.     if (verbose) {
  195.         verbose++;
  196.  
  197.         /* Copy up to the '|' character into terse */
  198.  
  199.         terse_length = strcspn(msg,"|");
  200.         strncpy(terse,msg,terse_length);
  201.         terse[terse_length] = '\0';
  202.     }
  203.  
  204.     /* If the main window is open, attatch requester to the open window. */
  205.  
  206.     if (mainwin)
  207.         window = mainwin;
  208.  
  209.     switch (err_no) {
  210.         case ERROR_WARNING:
  211.             if (!verbose) {
  212.                 /* Create the text string */
  213.  
  214.                 strncpy(reqtext,msg,STRLEN_EASYREQ);
  215.     
  216.                 /* Connect the text to the requester */
  217.  
  218.                 easyreq_warn.es_TextFormat = reqtext;
  219.  
  220.                 EasyRequest(window,&easyreq_warn,NULL);
  221.             }
  222.             else {
  223.                 /* Create the text string */
  224.  
  225.                 strncpy(reqtext,terse,STRLEN_EASYREQ);
  226.     
  227.                 /* Connect the text to the requester */
  228.  
  229.                 easyreq_more.es_TextFormat = reqtext;
  230.  
  231.                 if(EasyRequest(window,&easyreq_more,NULL)) {
  232.                     /* Create the text string */
  233.  
  234.                     strncpy(reqtext,verbose,STRLEN_EASYREQ);
  235.     
  236.                     /* Connect the text to the requester */
  237.  
  238.                     easyreq_warn.es_TextFormat = reqtext;
  239.  
  240.                     EasyRequest(window,&easyreq_warn,NULL);
  241.                 }
  242.             }
  243.             break;
  244.         case ERROR_FATAL:
  245.             if (!verbose) {
  246.                 /* Create the text string */
  247.  
  248.                 strncpy(reqtext,msg,STRLEN_EASYREQ);
  249.     
  250.                 /* Connect the text to the requester */
  251.  
  252.                 easyreq_fatal.es_TextFormat = reqtext;
  253.  
  254.                 EasyRequest(window,&easyreq_fatal,NULL);
  255.             }
  256.             else {
  257.                 /* Create the text string */
  258.  
  259.                 strncpy(reqtext,terse,STRLEN_EASYREQ);
  260.     
  261.                 /* Connect the text to the requester */
  262.  
  263.                 easyreq_fatalmore.es_TextFormat = reqtext;
  264.  
  265.                 if(EasyRequest(window,&easyreq_fatalmore,NULL)){
  266.                     /* Create the text string */
  267.  
  268.                     strncpy(reqtext,verbose,STRLEN_EASYREQ);
  269.     
  270.                     /* Connect the text to the requester */
  271.  
  272.                     easyreq_fatal.es_TextFormat = reqtext;
  273.  
  274.                     EasyRequest(window,&easyreq_fatal,NULL);
  275.                 }
  276.             }
  277.  
  278.             cleanup();
  279.             break;
  280.         case ERROR_INTERNAL:
  281.             /* Create the text string */
  282.  
  283.             sprintf(reqtext,"INTERNAL ERROR :\n%s\n"
  284. "Line %ld in file \"%s\"",msg,line,file);
  285.  
  286.             /* Connect the string to the requester */
  287.  
  288.             easyreq_internal.es_TextFormat = reqtext;
  289.  
  290.             EasyRequest(window,&easyreq_internal,NULL);
  291.  
  292.             cleanup();
  293.             break;
  294.         default:
  295.             EasyRequest(window,&easyreq_internal,NULL,"Unknown error  "
  296. "message",__LINE__,__FILE__);
  297.             cleanup();
  298.             break;
  299.     }
  300.  
  301.     /* Only unblock window if req code blocked it */
  302.  
  303.     if (unblock)
  304.         win_block_clear();
  305. }
  306.